package com.jade.store.pay.service.tencent.protocol.pay_unifiedorder;

/**
 * User: rizenguo
 * Date: 2014/10/22
 * Time: 16:42
 */

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
 * 被扫支付提交Post数据给到API之后，API会返回XML格式的数据，这个类用来装这些数据
 */
public class PayUnifiedorderResData {
    //协议层
    @XStreamAlias("return_code")
    private String return_code = "";
    @XStreamAlias("return_msg")
    private String return_msg = "";

    //协议返回的具体数据（以下字段在return_code 为SUCCESS 的时候有返回）
    @XStreamAlias("appid")
    private String appid = "";
    @XStreamAlias("mch_id")
    private String mch_id = "";
    @XStreamAlias("nonce_str")
    private String nonce_str = "";
    @XStreamAlias("sign")
    private String sign = "";
    @XStreamAlias("result_code")
    private String result_code = "";
    @XStreamAlias("err_code")
    private String err_code = "";
    @XStreamAlias("err_code_des")
    private String err_code_des = "";
    private String device_info = "";
    private String out_trade_no="";
    //业务返回的具体数据（以下字段在return_code 和result_code 都为SUCCESS 的时候有返回）
    @XStreamAlias("prepay_id")
    private String prepay_id = "";
    @XStreamAlias("trade_type")
    private String trade_type = "";
    @XStreamAlias("code_url")
    private String code_url = "";

    public String getReturn_code() {
        return return_code;
    }

    public void setReturn_code(String return_code) {
        this.return_code = return_code;
    }

    public String getReturn_msg() {
        return return_msg;
    }

    public void setReturn_msg(String return_msg) {
        this.return_msg = return_msg;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getMch_id() {
        return mch_id;
    }

    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }

    public String getNonce_str() {
        return nonce_str;
    }

    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getResult_code() {
        return result_code;
    }

    public void setResult_code(String result_code) {
        this.result_code = result_code;
    }

    public String getErr_code() {
        return err_code;
    }

    public void setErr_code(String err_code) {
        this.err_code = err_code;
    }

    public String getErr_code_des() {
        return err_code_des;
    }

    public void setErr_code_des(String err_code_des) {
        this.err_code_des = err_code_des;
    }

    public String getDevice_info() {
        return device_info;
    }

    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }

    public String getPrepay_id() {
        return prepay_id;
    }

    public void setPrepay_id(String prepay_id) {
        this.prepay_id = prepay_id;
    }

    public String getTrade_type() {
        return trade_type;
    }

    public void setTrade_type(String trade_type) {
        this.trade_type = trade_type;
    }

    public String getCode_url() {
        return code_url;
    }

    public void setCode_url(String code_url) {
        this.code_url = code_url;
    }

    /**
     * 根据xml数据获取Component_verify_ticket对象
     *
     * @param xml
     * @return
     */
    public PayUnifiedorderResData getReturnXml(String xml) {
        XStream xStream = new XStream(new DomDriver());
        xStream.alias("xml", this.getClass());
        // 设置成员的别名
        xStream.aliasField("return_code", this.getClass(), "return_code");
        xStream.aliasField("return_msg", this.getClass(), "return_msg");
        xStream.aliasField("result_code", this.getClass(), "result_code");
        PayUnifiedorderResData temp = (PayUnifiedorderResData) xStream.fromXML(xml);

        XStream newStream = new XStream(new DomDriver());
        newStream.alias("xml", this.getClass());
        if(temp.getReturn_code().equals("SUCCESS")){//返回成功
            newStream.aliasField("appid", this.getClass(), "appid");
            newStream.aliasField("mch_id", this.getClass(), "mch_id");
            newStream.aliasField("device_info", this.getClass(), "device_info");
            newStream.aliasField("result_code", this.getClass(), "result_code");
            newStream.aliasField("err_code", this.getClass(), "err_code");
            newStream.aliasField("err_code_des", this.getClass(), "err_code_des");
            if(temp.getResult_code().equals("SUCCESS")){
                newStream.aliasField("trade_type", this.getClass(), "trade_type");
                newStream.aliasField("prepay_id", this.getClass(), "prepay_id");
                newStream.aliasField("code_url", this.getClass(), "code_url");
            }
        }
        PayUnifiedorderResData authPush=(PayUnifiedorderResData) newStream.fromXML(xml);
        return authPush;
    }
}
